make implementation irrelevant; manipulate the concept, not the data
Any method f of class C should only call the methods of…
- C
- An object created by f
- An object passed as an argument to f
- An object held in an instance of C
…and should not call methods on objects returned from the allowed.
“Talk to friends, not to strangers.”
Long chains digging deeply into nested objects requires a function to know too much about the rest of the application, but data structures are fine.
Avoid: a mixed object and data structure; hard to add to, hard to change.
Objects do something; don’t ask for internals. Instead of asking for internals, move implementation into the object.
data structures which collect raw data (e.g. database row, socket data) into a known, compiler-parsable structure.
“Beans” are data transfer objects which have getters/setters for every property and no other methods
data structures with database methods only. Put business rules in separate classes.